package basicComp;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import gameElement.Dice;
import gameElement.Manager;

/**
 * 主控制框架
 * @author YHZNHQ
 *
 */
public class TestFrame {
	static int num = 4;
	public static void main(String [] args)
	{
		//建立框架
		JFrame j = new JFrame();
		j.setBounds(400, 100, 1000, 800);
		j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		j.setLayout(null);
		j.setResizable(false);
		//初始面板
		BasicMenuPane main = new BasicMenuPane(3, true);
		main.setBounds(0, 0, 1000, 800);
		main.init(100,50,70,true);
		main.transform(-200, 50);
		main.changeColor(new Color(154, 86, 42),new Color(135,67,23),new Color(154, 86, 42).darker());
		main.setNames(new String[]{"开始","游戏规则","退出"});
		main.setBackImage(ImageGet.getImageGet().getBeginning());
		
		//开始面板
		BasicMenuPane start = new BasicMenuPane(2, false);
		start.setBounds(0, 0, 1000, 800);
		start.init(100,50,150,false);
		start.transform(0, 200);
		start.setNames(new String[]{"确认","返回"});
		start.setBackImage(ImageGet.getImageGet().getSetNum());
		BasicArtButton two = new BasicArtButton("Two");
		two.setBounds(300, 300, 100, 50);
		start.add(two);
		BasicArtButton three = new BasicArtButton("Three");
		three.setBounds(450, 300, 100, 50);
		start.add(three);
		BasicArtButton four = new BasicArtButton("Four");
		four.setBounds(600, 300, 100, 50);
		start.add(four);
		two.addButtonListener( new ActionListener(){
			public void actionPerformed(ActionEvent e){
				num = 2;
			}
		});
		three.addButtonListener( new ActionListener(){
			public void actionPerformed(ActionEvent e){
				num = 3;
			}
		});
		four.addButtonListener( new ActionListener(){
			public void actionPerformed(ActionEvent e){
				num = 4;
			}
		});

		//游戏规则面板
		BasicMenuPane rule = new BasicMenuPane(1, false);
		rule.setBounds(0, 0, 1000, 800);
		rule.init(100,50,70,false);
		rule.setNames(new String[]{"返回"});
		rule.transform(0, 200);
		rule.setBackImage(ImageGet.getImageGet().getRule());
		rule.changeColor(new Color(154, 86, 42),new Color(135,67,23),new Color(154, 86, 42).darker());
		rule.transform(0, 50);
		
		//游戏面板
		BasicMenuPane gamePanel = new BasicMenuPane(2, false);
		gamePanel.setBounds(0, 0, 1000, 800);
		gamePanel.init(875, 628, 100, 50, 70, true);
		gamePanel.setNames(new String[]{"结束游戏","返回"});
		gamePanel.setBackImage(ImageGet.getImageGet().getChessBoard());
		gamePanel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				super.mouseClicked(e);
				if(!(e.getButton() == 1))
				{
					Dice.nextRoll++;
					if(Dice.nextRoll > 6)
					{
						Dice.nextRoll =1;
					}
					System.out.println("control dice = " + Dice.nextRoll);
				}
				{
//					System.out.println("new Point("+e.getX()+","+e.getY()+"),");
//					ChessPane.testP = e.getPoint();
				}
			}
		});
		Manager.getManager().iniChessPane(gamePanel);
		
		main.setButtonLink(0, start);
		main.setButtonLink(1, rule);
		main.setExitButton(2);
		gamePanel.setExitButton(0);
		gamePanel.setButtonLink(1, start);
		start.setButtonLink(0, gamePanel);
		start.setButtonLink(1, main);
		start.addButtonListener(0, new ActionListener(){
			public void actionPerformed(ActionEvent e) {
						Manager.getManager().start(num);
			}
		});
		
//		start.addButtonListener(0, new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				
//				
//				if(two.entered = true){
//					num = 2;
//				}
//				else{
//					if(three.entered == true){
//						num = 3;
//					}
//					else{
//						num =4;
//					}
//				}
//				Manager.getManager().start(num);
//				
//			}
//		});
		rule.setButtonLink(0, main);
		
		
		
		j.add(main);
		j.add(start);
		j.add(rule);
		j.add(gamePanel);
		
		j.setVisible(true);
	}
	
}
